package com.isay.frameworklib.widget.head;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.isay.frameworklib.R;

/**
 * tabView
 * Created by cywu4 on 2018/8/6.
 */

public class NormalHeadView extends LinearLayout implements View.OnClickListener {

    private TextView mTvTitle;

    private Activity mActivity;

    private NormalHeadViewListener mListener;

    public NormalHeadView(Context context) {
        super(context);
        initialize();
    }

    public NormalHeadView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initialize();
    }

    private void initialize() {
        View.inflate(getContext(), R.layout.view_head_normal, this);
        mTvTitle = findViewById(R.id.tv_title);
        findViewById(R.id.lay_back).setOnClickListener(this);
    }

    /**
     * 设置显示标题
     *
     * @param title 显示文字
     */
    public void setTitle(Activity ac, CharSequence title) {
        mActivity = ac;
        mTvTitle.setText(title);
    }


    /**
     * 设置监听
     *
     * @param l
     */
    public void setListener(NormalHeadViewListener l) {
        mListener = l;
    }


    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.lay_back) {
            if (mListener != null) {
                mListener.onBack();
            } else {
                if (mActivity != null) {
                    mActivity.finish();
                }
            }
        }
    }

    public interface NormalHeadViewListener {
        void onBack();
    }


}